Skip to content

Implement Generate Functionality: fix ProjectWorker config structure, add CLAP support, cleanup, and test coverage - #57

Merged
SeamusMullan merged 4 commits into
mainfrom
copilot/implement-generate-functionality
Apr 3, 2026
Merged

Implement Generate Functionality: fix ProjectWorker config structure, add CLAP support, cleanup, and test coverage#57
SeamusMullan merged 4 commits into
mainfrom
copilot/implement-generate-functionality

Conversation

Copilot AI commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

ProjectWorker was silently discarding user-configured values and missing format support, causing generated projects to not reflect the actual configuration filled in by the user.

Fixes in src/core/project_worker.py

  • version ignored – params value now takes precedence over VERSION file; file/default only consulted as fallback
  • plugin_code always regenerated – user-supplied code is now used; generate_plugin_id() is only called when the field is blank
  • CLAP format never emitted – added options["clap"] → "CLAP" branch (was silently dropped from CMakeLists.txt)
  • clone_template_repo() hardened – raises RuntimeError when output_directory is empty or already exists; falls back to DEFAULT_TEMPLATE_URL when fork_url is blank
  • No cleanup on failure – added _cleanup_on_failure() (removes partial output dir); run() now calls it before emitting the error signal
  • git commit fails without global configinit_git_repo() now passes GIT_AUTHOR_*/GIT_COMMITTER_* env var fallbacks so the initial commit succeeds in CI or unconfigured environments
# Before: plugin_code from UI discarded, CLAP never in formats, version always "0.0.1"
plugin_code = generate_plugin_id()          # always random
# "clap" branch missing from formats list
version = "0.0.1"                           # ignores params["version"]

# After
plugin_code = (self.params.get("plugin_code", "") or "").strip() or generate_plugin_id()
if self.options.get("clap", False):
    formats.append("CLAP")
version = self.params.get("version", "").strip() or version_from_file_or_default

New tests/test_project_worker.py

39 unit tests covering: version/plugin-code param precedence, CLAP inclusion, clone pre-flight validation, default URL fallback, cleanup-on-failure, and git author env var injection.

Copilot AI linked an issue Apr 3, 2026 that may be closed by this pull request
7 tasks
Copilot AI changed the title [WIP] Implement project generation functionality Implement Generate Functionality: fix ProjectWorker config structure, add CLAP support, cleanup, and test coverage Apr 3, 2026
Copilot AI requested a review from SeamusMullan April 3, 2026 13:43
@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown

📊 PR Summary

Changes Overview

  • Files Changed: 2
  • Python Files: 2
  • Test Files: 1
  • Documentation: 0
  • Added: 1
  • Deleted: 0

CI Checks

This PR will trigger the following checks:

  • ✅ Linting (ruff, isort, black)
  • ✅ Type Checking (mypy)
  • ✅ Tests (pytest)

Please ensure all checks pass before merging.

@SeamusMullan

Copy link
Copy Markdown
Member

@copilot fix lint fails

Copilot AI review requested due to automatic review settings April 3, 2026 18:40
@SeamusMullan
SeamusMullan merged commit 8325cf3 into main Apr 3, 2026
5 checks passed
@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown

📊 PR Summary

Changes Overview

  • Files Changed: 2
  • Python Files: 2
  • Test Files: 1
  • Documentation: 0
  • Added: 1
  • Deleted: 0

CI Checks

This PR will trigger the following checks:

  • ✅ Linting (ruff, isort, black)
  • ✅ Type Checking (mypy)
  • ✅ Tests (pytest)

Please ensure all checks pass before merging.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes ProjectWorker project-generation behavior so user-provided configuration is consistently honored (version, plugin code, format selection), hardens template cloning defaults/validation, improves failure cleanup, and adds dedicated unit test coverage for these behaviors.

Changes:

  • Fix configuration precedence in prepare_project_variables() (version and plugin code) and add missing CLAP format emission.
  • Harden clone_template_repo() (output directory validation + default template URL fallback) and add cleanup-on-failure behavior in run().
  • Add comprehensive unit tests for the updated ProjectWorker behaviors, including git author env injection during the initial commit.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/core/project_worker.py Adds default template URL fallback, cleanup-on-failure, fixes params precedence for version/plugin code, and adds CLAP format support plus git author env injection.
tests/test_project_worker.py Introduces a new test suite covering the corrected generation logic, clone validation/fallback, cleanup behavior, and git env handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if os.path.exists(output_dir):
raise RuntimeError(f"Output directory already exists: {output_dir}")

fork_url = self.params.get("fork_url", "") or DEFAULT_TEMPLATE_URL

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fork_url falls back to DEFAULT_TEMPLATE_URL only when the param is falsy. A whitespace-only value (e.g. " ") will bypass the fallback and be passed to git clone, which will fail. Consider normalizing with .strip() (similar to plugin_code/version) before applying the default URL.

Suggested change
fork_url = self.params.get("fork_url", "") or DEFAULT_TEMPLATE_URL
fork_url = str(self.params.get("fork_url", "")).strip() or DEFAULT_TEMPLATE_URL

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +78
except Exception:
pass

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_cleanup_on_failure() suppresses all exceptions during shutil.rmtree(...) with a bare except Exception: pass. If cleanup fails (permissions, locked files, etc.) it will be silently ignored, leaving partial output behind with no visibility. Consider at least emitting a progress/error message (or logging) with the exception details so failures are diagnosable.

Suggested change
except Exception:
pass
except Exception as e:
self.error.emit(
f"Failed to clean up partial output directory '{output_dir}': {e!s}"
)

Copilot uses AI. Check for mistakes.
Comment on lines +365 to +366
# The commit call is the third subprocess.run call (init, add, commit)
commit_call = mock_run.call_args_list[2]

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test assumes the git commit invocation is always the 3rd subprocess.run call (call_args_list[2]). That’s brittle if init_git_repo() adds another git command later (e.g., setting config, creating branches). Consider locating the commit call by scanning call_args_list for an entry whose argv contains "commit", then asserting on its kwargs.

Suggested change
# The commit call is the third subprocess.run call (init, add, commit)
commit_call = mock_run.call_args_list[2]
commit_call = next(
(
call
for call in mock_run.call_args_list
if call.args
and call.args[0]
and "commit" in call.args[0]
),
None,
)
assert commit_call is not None

Copilot uses AI. Check for mistakes.
@SeamusMullan
SeamusMullan deleted the copilot/implement-generate-functionality branch April 4, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[EPIC] Implement Generate Functionality

3 participants